<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeBehind="FormView.aspx.cs" Inherits="www.Update_FormView" Title="Untitled Page" %>

<%@ Register Assembly="NBusiness" Namespace="NBusiness.Data.Web" TagPrefix="cc1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <asp:FormView ID="FormView1" runat="server" DataKeyNames="BeerId" 
        DefaultMode="Edit" HeaderText="&nbsp;" Width="50%"
        Visible="false" Enabled="false" OnItemCommand="FormView1_ItemCommand" OnItemUpdating="FormView1_ItemUpdating">
        <EditItemTemplate>
            <table>
                <tr>
                    <td style="width: 30%; font-weight: bold;">BeerId:</td>
                    <td style="width: 70%;"><asp:Label ID="Label1" runat="server" Text='<%# Bind("BeerId") %>'></asp:Label></td>
                </tr>
                <tr>
                    <td style="width: 30%; font-weight: bold;">AvailabilityId:</td>
                    <td style="width: 70%;"><asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="AvailabilityCollectionDS" Width="200px"
                            DataTextField="Text" DataValueField="AvailabilityId" SelectedValue='<%# Bind("AvailabilityId") %>'>
                        </asp:DropDownList></td>
                </tr>
                <tr>
                    <td style="width: 30%; font-weight: bold;">Alcohol</td>
                    <td style="width: 70%;"><asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Alcohol") %>' Width="200px"></asp:TextBox></td>
                </tr>
                <tr>
                    <td style="width: 30%; font-weight: bold;">BeerStyleId</td>
                    <td style="width: 70%;"><asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="BeerStyleCollectionDS" Width="200px"
                        DataTextField="Name" DataValueField="BeerStyleId" SelectedValue='<%# Bind("BeerStyleId") %>'>
                        </asp:DropDownList></td>
                </tr>
                <tr>
                    <td style="width: 30%; font-weight: bold;">CompanyId</td>
                    <td style="width: 70%;"><asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="CompanyCollectionDS" Width="200px"
                        DataTextField="Name" DataValueField="CompanyId" SelectedValue='<%# Bind("CompanyId") %>'>
                        </asp:DropDownList></td>
                </tr>
                <tr>
                    <td style="width: 30%; font-weight: bold;">Name</td>
                    <td style="width: 70%;"><asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("Name") %>' Width="200px"></asp:TextBox></td>
                </tr>
            </table>
        </EditItemTemplate>
        <FooterTemplate>
            <asp:LinkButton ID="UpdateBtn" runat="server" CausesValidation="False" CommandName="Update"
                Text="Update"></asp:LinkButton>
            <asp:LinkButton ID="CancelBtn" runat="server" CausesValidation="False" CommandName="Cancel"
                Text="Cancel"></asp:LinkButton>
        </FooterTemplate>                  
    </asp:FormView>
    <p>Upon selecting a Beer to update a FormView control will appear.</p>
    <!-- GridView Display BeerList -->
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="BeerId"
        DataSourceID="BeerCollectionDS" OnRowDataBound="GridView1_RowDataBound"
        Width="100%" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
        <Columns>
            <asp:TemplateField ShowHeader="False">
                <ItemTemplate>
                    <asp:LinkButton ID="SelectToUpdate" runat="server" CausesValidation="False" CommandName="Select"
                        Text="Select"></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="AvailabilityId" SortExpression="AvailabilityId">
                <ItemTemplate>
                    <asp:HyperLink ID="AvailabilityLink" runat="server" NavigateUrl='<%# Eval("AvailabilityId", "~/Search/ByAvailability.aspx?a={0}") %>'></asp:HyperLink>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="BeerId" HeaderText="BeerId" InsertVisible="False" ReadOnly="True"
                SortExpression="BeerId" />
            <asp:TemplateField HeaderText="Alcohol" SortExpression="Alcohol">
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("Alcohol") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="BeerStyleId" SortExpression="BeerStyleId">
                <ItemTemplate>
                    <asp:HyperLink ID="StyleLink" runat="server" NavigateUrl='<%# Eval("BeerStyleId", "~/Search/ByStyle.aspx?s={0}") %>'></asp:HyperLink>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="CompanyId" SortExpression="CompanyId">
                <ItemTemplate>
                    <asp:HyperLink ID="CompanyLink" runat="server" NavigateUrl='<%# Eval("CompanyId", "~/Company.aspx?c={0}") %>'></asp:HyperLink>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Name" SortExpression="Name">
                <ItemTemplate>
                    <asp:Label ID="Label5" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    <!-- Data Source -->
    <cc1:EntityDataSource ID="BeerDS" runat="server" AssemblyName="Example.Entities, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
        TypeName="BeerBase.Business.Beer" OnSelect="BeerItemDataSource_Select">
    </cc1:EntityDataSource>
    <cc1:EntityDataSource ID="BeerCollectionDS" runat="server" AssemblyName="Example.Entities, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
        TypeName="BeerBase.Business.BeerCollection" OnSelect="BeerDataSource_Select">
    </cc1:EntityDataSource>
    <cc1:EntityDataSource ID="AvailabilityCollectionDS" runat="server" AssemblyName="Example.Entities, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
        TypeName="BeerBase.Business.CachedAvailabilityCollection" OnSelect="AvailDataSource_Select">
    </cc1:EntityDataSource>
    <cc1:EntityDataSource ID="BeerStyleCollectionDS" runat="server" AssemblyName="Example.Entities, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
        TypeName="BeerBase.Business.CachedBeerStyleCollection" OnSelect="BeerStyleDataSource_Select">
    </cc1:EntityDataSource>
    <cc1:EntityDataSource ID="CompanyCollectionDS" runat="server" AssemblyName="Example.Entities, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
        TypeName="BeerBase.Business.CompanyCollection" OnSelect="CompanyDataSource_Select">
    </cc1:EntityDataSource>
</asp:Content>